menuFlag<!--  -->
<template>
  <div class='home'>
    <el-container>
      <el-aside :width="menuFlag ? '200px' : '40px'">
        <div>
          <img width="100%" style="margin-top: 7px;" src="http://www.jxslsd.com/images2/logo1.jpg" alt="">
          <el-menu default-active="1" class="el-menu-vertical-demo" background-color="#545c64" text-color="#fff"
            active-text-color="#ffd04b">

            <el-menu-item v-for="item in menuList" :key="item.id" :index="item.index" @click="menuClick(item)">
              <i :class="item.icon"></i>
              <span v-if="menuFlag" slot="title">{{ item.title }}</span>
            </el-menu-item>
          </el-menu>
        </div>
      </el-aside>

      <el-container>
        <el-header>
          <div>
            <i @click="menuFlag = !menuFlag" :class="menuFlag ? 'el-icon-s-fold' : 'el-icon-s-unfold'"></i>
            <span style="margin-left:5px ;">{{ menuItem.title }}</span>
          </div>
          <div style="display: flex; align-items: center;">
            <img style="border-radius: 50%;margin-right: 8px;" height="45" width="45" src="../assets/user_img.png"
              alt="">
            <el-dropdown trigger="click" @command="handleCommand">
              <span class="el-dropdown-link">{{ userInfo.roleName }}<i class="el-icon-arrow-down el-icon--right"></i></span>
               <el-dropdown-menu slot="dropdown">
                <el-dropdown-item command="1">退出登录</el-dropdown-item>
                </el-dropdown-menu>
            </el-dropdown>

            
            
          </div>


        </el-header>
        <el-main>
          <router-view />
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
export default {
  //import引入的组件需要注入到对象中才能使用
  components: {},
  data() {
    //这里存放数据
    return {
      userInfo: {

      },
      menuList: [
        {
          id: 1,
          title: '首页',
          icon: 'el-icon-s-grid',
          index: '1',
          path: '/'
        },
        {
          id: 2,
          title: '组织',
          icon: 'el-icon-s-grid',
          index: '2',
          path: '/organization'
        },
        {
          id: 3,
          title: '角色',
          icon: 'el-icon-s-grid',
          index: '3',
          path: '/role'
        },
        {
          id: 4,
          title: '人员',
          icon: 'el-icon-s-grid',
          index: '4',
          path: '/person'
        },
        {
          id: 5,
          title: '考核',
          icon: 'el-icon-s-grid',
          index: '5',
          path: '/examine'
        }
      ],
      menuItem: {},
      menuFlag: true
    };
  },
  //监听属性 类似于data概念
  computed: {},
  //监控data中的数据变化
  watch: {},
  //方法集合
  methods: {
    menuClick(item) {
      this.menuItem = item
      if (this.$route.path == item.path) {
        return
      } else {
        this.$router.push(item.path)
      }
    },
    handleCommand(e) {
      if (e == 1) {
        localStorage.removeItem("userInfo")
        this.$router.push('/login')
      }
    },
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {
    this.menuItem = this.menuList[0]
    let userInfo = localStorage.getItem('userInfo')
    this.userInfo = userInfo ? JSON.parse(userInfo) : {}
  },
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {

  },
  beforeCreate() { }, //生命周期 - 创建之前
  beforeMount() { }, //生命周期 - 挂载之前
  beforeUpdate() { }, //生命周期 - 更新之前
  updated() { }, //生命周期 - 更新之后
  beforeDestroy() { }, //生命周期 - 销毁之前
  destroyed() { }, //生命周期 - 销毁完成
  activated() { }, //如果页面有keep-alive缓存功能，这个函数会触发
}
</script>
<style lang='less' scoped>
.el-container {
  height: 100vh;
}

.el-header,
.el-footer {
  background-color: #B3C0D1;
  color: #333;
  text-align: center;
  // line-height: 60px;
}

.el-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.el-aside {
  background-color: #6e6e6e;
  color: #333;
  text-align: center;
  // line-height: 200px;
}

.el-main {
  background-color: #E9EEF3;
  color: #333;
  // text-align: center;
  // line-height: 160px;
}

.el-menu {
  margin-top: 3px;
  border-right: none;
}

.el-menu-item {
  padding: 0 !important;
}
</style>